package morefun.demo

import org.apache.spark.{SparkConf, SparkContext}

object BroadcastVariable {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("BroadcastVariable ").setMaster("local")
    val sc = new SparkContext(conf)
    val numList = sc.parallelize(Array(1,2,3,4,5,6,7,8,9,10))

    val factor = 3 //
//    1. 广播变量 Broadcast  Variable
//      1. 每个节点拷贝一份，不能夸节点累加
    val factorBroadcast = sc.broadcast(factor)
    val number = numList.map( num => num * factorBroadcast.value)

    number.foreach( println(_))

  }
}
